package NetModel.okhttp.requset;

import android.net.Uri;


import java.util.Map;

import NetModel.okhttp.OkHttpClientManger;
import okhttp3.Call;
import okhttp3.Request;

/**
 * Created by Administrator on 2016/10/27.
 */
public class GetRequestBuilder extends BaseRequest<GetRequestBuilder> {


    @Override
    public Call build() {
        Request req = new Request.Builder().get()
                .url(addGetParams(url))
                .tag(tag)
                .headers(addHead(heads))
                .build();
        Call call = OkHttpClientManger.getInstance().getClient().newCall(req);
        return call;
    }


    private String addGetParams(String url) {
        if (params != null && !params.isEmpty()) {
            Uri.Builder urlBuilder = Uri.parse(url).buildUpon();
            for (Map.Entry<String, String> entry : params.entrySet()) {
                urlBuilder.appendQueryParameter(entry.getKey(), entry.getValue());
            }
            return urlBuilder.build().toString();
        } else {
            return url;
        }
    }


}
